package com.flyduck.system.controller;

import com.flyduck.common.annotation.IgnoreAuth;
import com.flyduck.common.util.TokenUtil;
import com.flyduck.system.service.LoginService;
import com.flyduck.system.vo.login.LoginReqVO;
import com.flyduck.common.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @program: flyduck-platform
 * @description: 系统:登录接口
 * @author: flyduck
 * @create: 2021-02-02 21:10
 **/
@Api(tags = "系统:登录接口")
@RestController
@RequestMapping("/system/login")
public class LoginController {

    @Autowired
    private LoginService loginService;
    @Autowired
    private TokenUtil tokenUtil;

    @ApiOperation("获取验证码")
    @GetMapping("/code")
    public Result getCode(){
        Map<String, String> resultMap = loginService.getCode();
        return Result.success(resultMap);
    }

    @ApiOperation("登录")
    @PostMapping("/login")
    public Result login(@RequestBody LoginReqVO reqVO){
        String token = loginService.login(reqVO);
        return Result.success(token,"登录成功");

    }
    @IgnoreAuth
    @ApiOperation("获取用户信息")
    @GetMapping("/info")
    public Result getInfo(){
        return Result.success( tokenUtil.getLoginInfo());
    }

    @ApiOperation("退出登录")
    @PostMapping("/logout")
    public Result logout(){
        return Result.success("注销成功");
    }

}
